<?php
include_once("../modules/checkA.php");
include_once("../../config.php");
$plate=select_one_line_all_items($table_Prefix."plate","mid = 'finance'");
?>


<?
//用来判断当前系统属于什么板块
$system_part = $plate['mid'];
if(!$_REQUEST ['applydate'])
{
    $_REQUEST ['applydate']=date("Y-m");
}
$applydate  = addslashes($_REQUEST ['applydate']);
?>



<?
//获取部门的 nid名字对应表
$department_full_list=select_lines_all_items($table_Prefix."department","","","");
$department_list=transform_2darray_in_1darray_with_new_key($department_full_list,"nid","name");

//获取员工的 nid名字对应表
$employee_full_list=select_lines_all_items($table_Prefix."employee","","","");
$employee_list=transform_2darray_in_1darray_with_new_key($employee_full_list,"nid","name");



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
       <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'modules/head.php'; ?>

</head>

<body>

<div id="topbar">   <?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>




        <div id="content">
            <h1>财务明细</h1>

            <input name="print" type="button" id="bt" value="点击打印" class="layui-btn" onclick="print_btn('div_print')"/>



            <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
            <div class="list-box">

                <div class="statistic">


                    <div class="term-select-function">
                        <label class="layui-form-label">筛选：</label>
                        <div class="layui-input-block">

                            <?
                            $oldest_men=select_one_line_all_items($table_Prefix."finance","nid > 0 order by applydate asc");


                            date_default_timezone_set('Asia/Shanghai');
                            $first_day_of_month = date('Y-m',time()) . '-01 00:00:01';
                            $t = strtotime($first_day_of_month);

                            $oldest_month=substr($oldest_men['applydate'],0,7);

                            $endmark=10000;

                            for ($i = 0; $i < $endmark; $i++) {



                                if(date("Y-m",strtotime("-$i month",$t))==$oldest_month)
                                {
                                    $endmark=0;
                                    $showdate[$i]=date("Y-m",strtotime("-$i month",$t));
                                }
                                else
                                {

                                    $showdate[$i]=date("Y-m",strtotime("-$i month",$t));
                                }


                            }


                            ?>


                            <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
                                <option value=""> </option>
                                <?php
                                for ($i = 0; $i < count($showdate); $i++) {
                                    ?>
                                    <option value="list.php?applydate=<? echo $showdate[$i] ?>&nav-itemed=<? echo $system_part ?>"> <? echo $showdate[$i];?> </option>
                                    <?;}?>
                            </select>

                        </div>
                    </div>


                </div>


         <br class="clearfloat"/>





                <div id="div_print">
                <div class="detail-staitics-info" >



                    <?

$sumcost=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and applydate like '%".$applydate."%' ");
$sumcost_weixiu=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%' and classify = '维修费' ");
$sumcost_lingjiangoumai=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '零件购买' ");
$sumcost_goumaibaoxian=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '购买保险' ");
$sumcost_yewufei=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%' and classify = '业务费' ");
$sumcost_shebeigouzhifei=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '设备购置费' ");
$sumcost_yewuzhaodaifei=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '业务招待费' ");
$sumcost_bangongyongpin=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '办公用品' ");
$sumcost_qita=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '其他' ");

                    $sumcost_huoshizhichu=sum_total($table_Prefix."finance","cost", "(rid is null or rid = '0') and  applydate like '%".$applydate."%'  and classify = '伙食支出' ");





                    ?>
                    <ul>

                        <li><label>本月合计支出:</label>
                            <?echo $sumcost;?>
                            <b> 元</b>
                        </li>




                        <br class="clearfloat"/>

                        <li><label>维修费:</label>
                            <?echo $sumcost_weixiu;?>
                            <b> 元</b>
                        </li>

                        <li><label>零件购买:</label>
                            <?echo $sumcost_lingjiangoumai;?>
                            <b> 元</b>
                        </li>

                        <li>
                            <label>购买保险:</label>
                            <?echo $sumcost_goumaibaoxian;?>
                            <b> 元</b>
                        </li>

                        <li>
                            <label>业务费:</label>
                            <?echo $sumcost_yewufei;?>
                            <b> 元</b>
                        </li>

                        <li>
                            <label>设备购置费:</label>
                            <?echo $sumcost_shebeigouzhifei;?>
                            <b> 元</b>
                        </li>

                        <li>
                            <label>业务招待费:</label>
                            <?echo $sumcost_yewuzhaodaifei;?>
                            <b> 元</b>
                        </li>

                        <li>
                            <label>办公用品:</label>
                            <?echo $sumcost_bangongyongpin;?>
                            <b> 元</b>
                        </li>

                        <li>
                            <label>伙食支出:</label>
                            <?echo $sumcost_huoshizhichu;?>
                            <b> 元</b>
                        </li>


                        <li>
                            <label>其他:</label>
                            <?echo $sumcost_qita;?>
                            <b> 元</b>
                        </li>




                    </ul>

                    <hr/>
                <div class="list-boxes ">





                    <?

                    for($i=1;$i<=date("t",$applydate);$i++)
                    {





                        unset($detail);unset($sum_cost);

                        $day=str_pad($i,2,"0",STR_PAD_LEFT);




                        //超过今天的，就不再循环了。
//                        echo $applydate."-".$day;
//                        echo "<br/>";
//                        echo date("Y-m-d");

                        if($applydate."-".$day==date("Y-m-d"))
                        {
                            $i=32;
                        }







                        ?>


<div>
<span class="layui-btn layui-btn-small" onclick="print_btn(<?echo "'t".$day."'"?>)">打印本日明细</span>
<?echo $applydate."-".$day;?>
</div>

<div class="layui-form inprint" id="t<?echo $day?>" >
<style>
.inprint{ font-size:10px!important;}
</style>




    <table class="layui-table">
        <colgroup>
            <col width="60">
            <col width="250">
            <col >
            <col >
            <col >
            <col >
            <col >
            <col >
            <col width="200">
            <col width="350">
        </colgroup>
        <thead>
        <tr>

            <th>序号</th>
            <th>内容</th>
            <th>金额</th>
            <th>用款人</th>
            <th>部门</th>
            <th>录入</th>
            <th>类型</th>
            <th>日期</th>
            <th>状态</th>
            <th>备注</th>
        </tr>
        </thead>
        <tbody>




<?
$detail=select_lines_all_items($table_Prefix."finance","","(rid is null or rid = '0') and applydate like '%".$applydate."-".$day."%'","");
 ?>

<?php
for ($ii = 0; $ii < count($detail); $ii++) {
    ?>

    <tr <? if ($applymodify['nid']) {
        echo "style='color:red'";
        $status = "审核中";
    } else {
        $status = "正常";
    } ?>>
        <td><? echo $ii + 1 ?></td>
        <td><? echo $detail[$ii]['name'] ?></td>
        <td><? echo $detail[$ii]['cost'] ?></td>
        <td><? echo $employee_list[$detail[$ii]['principal']] ?></td>
        <td><? echo $department_list[$detail[$ii]['departmentid']] ?></td>
        <td><? echo $employee_list[$detail[$ii]['authur']] ?></td>
        <td><? echo $detail[$ii]['classify'] ?></td>
        <td><? echo substr($detail[$ii]['applydate'], 11) ?> </td>
        <td><? echo $detail[$ii]['status'] ?> </td>
        <td><? echo $detail[$ii]['remark'] ?> </td>


    </tr>


    <? $sum_cost[$ii] = $detail[$ii]['cost'] ?>

    <?php
    ;
}
?>

<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>

    <td></td>
    <td>总金额：<? echo array_sum($sum_cost) ?></td>
    <td></td>
    <td></td>
</tr>

                        </tbody>
                    </table>

</div>




                    <?
                    ;}
                    ?>





















                </div>
                </div>




                <!--list-box end-->
            </div>

            <!--content端點01-->
        </div>
        <!--maincontent端點01-->
        <br class="clearfloat"/>
    </div>
    <!--container端點01-->
</div>











<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
